﻿
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Text
Imports System.Xml
Imports System.IO

Namespace GlobalClass
    Class GlobalFunction

#Region "Phuong thuc khoi tao"
        Public Sub New()

        End Sub
#End Region

#Region "Phương thức hành động"
        'Hàm chuỷên đổi ngày tháng theo định dạng
        Public Shared Function DateTimeConverter(ByVal [date] As String, ByVal dateFormat As String) As DateTime
            If [date].Trim() <> "" Then
                Dim dateTimeConverted As New DateTime()

                Dim delimStr As String = "\/- "
                Dim delimiter As Char() = delimStr.ToCharArray()
                Dim split As String() = Nothing

                For x As Integer = 1 To 3
                    split = [date].Split(delimiter)
                Next

                Select Case dateFormat.ToLower().Trim()
                    Case "mdy"
                        dateTimeConverted = New DateTime(Convert.ToInt32(split(2).ToString()), Convert.ToInt32(split(0).ToString()), Convert.ToInt32(split(1).ToString()))
                        Exit Select
                    Case "dmy"
                        dateTimeConverted = New DateTime(Convert.ToInt32(split(2).ToString()), Convert.ToInt32(split(1).ToString()), Convert.ToInt32(split(0).ToString()))
                        Exit Select
                    Case "ymd"
                        dateTimeConverted = New DateTime(Convert.ToInt32(split(0).ToString()), Convert.ToInt32(split(1).ToString()), Convert.ToInt32(split(2).ToString()))
                        Exit Select
                    Case "ydm"
                        dateTimeConverted = New DateTime(Convert.ToInt32(split(0).ToString()), Convert.ToInt32(split(2).ToString()), Convert.ToInt32(split(1).ToString()))
                        Exit Select
                    Case Else
                        dateTimeConverted = DateTime.Now
                        Exit Select
                End Select

                Return dateTimeConverted
            Else
                Return DateTime.Now
            End If
        End Function
        Public Shared Sub DuyetCtr(ByVal sW As StreamWriter, ByVal ctr As Control)
            Dim tagXML As String = "<" + ctr.Name + ">" + ctr.Text + "</" + ctr.Name + ">"
            sW.WriteLine(tagXML)
            'tagXML = "Eng" + "<" + ctr.Name + ">" + ctr.Text + "</" + ctr.Name + ">"
            sW.WriteLine(tagXML)
            If (ctr.HasChildren) Then
                For Each chilCtr As Control In ctr.Controls
                    DuyetCtr(sW, chilCtr)
                Next
            End If
        End Sub
        Public Shared Sub GhiTenControlToXML(ByVal ctr As Control, ByVal tenFile As String)
            Dim streamW As New StreamWriter("frmMain.xml")
            DuyetCtr(streamW, ctr)
            streamW.Close()
        End Sub

#End Region

    End Class
End Namespace

